﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;

namespace SPCAM.Utils
{
    public static class Tools
    {
        //创建一个外部静态资源转为图片地址赋值给XAML的方法
        public static BitmapImage PathToImg(string path)
        {
            BitmapImage bitmap = new BitmapImage();

            // 初始化 BitmapImage
            bitmap.BeginInit();
            ///SpCam.Resources;component/icon/Cam.png
            ///  bitmap.UriSource = new Uri("pack://application:,,,/Resources/your_image.png", UriKind.Absolute);
   

            bitmap.UriSource = new Uri($"pack://application:,,,{path}", UriKind.Absolute);
            bitmap.EndInit();

            // 将图片资源设置为 Image 控件的源
            return bitmap;

        }
        /// <summary>
        /// 图片资源转图片,
        /// </summary>
        /// <param name="_namespace">命名空间</param>
        /// <param name="path">路径</param>
        /// <returns></returns>
        public static BitmapImage PathToImg(Type _namespace,string path)
        {
          string name=  _namespace.Namespace;
            BitmapImage bitmap = new BitmapImage();

            // 初始化 BitmapImage
            bitmap.BeginInit();
            ///SpCam.Resources;component/icon/Cam.png
            ///   bitmap.UriSource = new Uri("pack://application:,,,/YourAssemblyName;component/Resources/your_image.png", UriKind.Absolute);

            bitmap.UriSource = new Uri($"pack://application:,,,/{name};component/{path}", UriKind.Absolute);
            bitmap.EndInit();

            // 将图片资源设置为 Image 控件的源
            return bitmap;

        }
    }
}
